#!/bin/bash

# define the exit code which should be corresponding to nagios exitcode
OK=0
WARNING=1
CRITICAL=2

# check the existence of condor master process
if [[ `/bin/ps -ef |/bin/grep -w 'condor_master' |/bin/grep -v 'grep' |/bin/wc -l` -eq 0 ]];
then
	echo "WARNING: condor_master is lost."
	exit $WARNING
fi

# check the existence of condor startd process
if [[ `/bin/ps -ef |/bin/grep -w 'condor_startd' |/bin/grep -v 'grep' |/bin/wc -l` -eq 0 ]];
then
	echo "WARNING: condor_startd is lost."
	exit $WARNING
# check if condor startd is managed by init process(process 1)
elif [[ `/bin/ps -ef |/bin/grep -w 'condor_startd' |/bin/grep -v 'grep' | /bin/awk '{print $3}'` -eq 1 ]];
then
	echo "WARNING: condor_startd lost its real father and hosted by init process."
	exit $WARNING
fi

# return a good status to nagios
echo "status is ok"
exit $OK
